﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using ExtAspNet;
using Ylh.BLL;

public partial class Module_CustServerManger_MyServerCustInfo : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["CustServerID"]!=null)
            {
                 Loaddata(Request.QueryString["CustServerID"].ToString());
            }
           
        }
    }


    private void Loaddata(string CustServerID)
    {
        Ylh.BLL.CustServerBLL blls = new Ylh.BLL.CustServerBLL(DbConnectionStr);
        Ylh.Model.TbCustServer model = blls.GetModel(Convert.ToInt32(CustServerID));

        this.CustServerID.Text = CustServerID;

        this.ServerTime.SelectedDate = Convert.ToDateTime(model.ServerTime);
        this.FollowTime.SelectedDate = Convert.ToDateTime(model.FollowTime);
        this.ReportSendTime.Text = model.ReportSendTime.ToString();
        this.Feedback.Text = model.Feedback;
        this.ServerDetailed.Text = model.ServerDetailed;
        this.Remark.Text = model.Remark;
    }

    private Ylh.Model.TbCustServer GetModel()
    {
        int CustID =Convert.ToInt32( Request.QueryString["CustID"]);
        int StaffID = int.Parse(base.StaffID.ToString());
        DateTime ServerTime = DateTime.Parse(this.ServerTime.Text);
        DateTime FollowTime = DateTime.Parse(this.FollowTime.Text);
        DateTime ReportSendTime = DateTime.Parse(this.ReportSendTime.Text);
        string Feedback = this.Feedback.Text;
        string ServerDetailed = this.ServerDetailed.Text;
        string Remark = this.Remark.Text;


        Ylh.Model.TbCustServer model = new Ylh.Model.TbCustServer();
        if (!string.IsNullOrEmpty(CustServerID.Text))
        {
 model.CustServerID =Convert.ToInt32( this.CustServerID.Text);
        }
       

        model.CustID = CustID;
        model.StaffID = StaffID;
        model.ServerTime = ServerTime;
        model.FollowTime = FollowTime;
        model.ReportSendTime = ReportSendTime;
        model.Feedback = Feedback;
        model.ServerDetailed = ServerDetailed;
        model.Remark = Remark;

        return model;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (string .IsNullOrEmpty(ServerTime.Text))
        {
            Alert.Show("请先填写服务时间");
            return;
        }


        Ylh.BLL.CustServerBLL blls = new CustServerBLL(DbConnectionStr);
        Ylh.Model.TbCustServer server = GetModel();



        if (string.IsNullOrEmpty(CustServerID.Text))
        {
           CustServerID.Text= blls.InserServer(server).ToString();
                
            Alert.Show("服务信息添加成功");
        }
        else
        {
            blls.UpdateServer(server);
            Alert.Show("服务信息修改成功");
        }

    }
}